package com.yasenagat;

import java.lang.reflect.Constructor;

import org.apache.thrift.TProcessor;
import org.apache.thrift.TProcessorFactory;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TBinaryProtocol.Factory;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.server.TNonblockingServer;
import org.apache.thrift.server.TServer;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TNonblockingServerSocket;

public class Server {

	public static void main(String[] args) {
		
		
		try {
//			TServerSocket serverTransport = new TServerSocket(7911);
			Something.Processor processor = new Something.Processor(new SomethingImpl());
			Factory protFactory = new TBinaryProtocol.Factory(true,true);
////			Args args2 = new Args(serverTransport);
////			args2.processor(processor);
//			TServer server = new TThreadPoolServer(processor,serverTransport,protFactory);
//			server.serve();
			
			TNonblockingServerSocket socket = new TNonblockingServerSocket(
					8888);
//			Class classhandle = Class.forName(model.getHandler()); com.caitong.thriftserviceimpl.UserServiceImpl
//			Class classprocess = Class.forName(model.getProcess()); com.caitong.thriftservice.UserService$Processor
//			String iface=model.getProcess().substring(0, model.getProcess().indexOf("$"))+"$Iface";
//			Constructor constructor=classprocess.getConstructor(Class.forName(iface));
			TNonblockingServer.Args arg = new TNonblockingServer.Args(
					socket);
			arg.protocolFactory(new TCompactProtocol.Factory());
			arg.transportFactory(new TFramedTransport.Factory());
			arg.processorFactory(new TProcessorFactory(processor));
//			System.out.println("Server is start Port:" + model.getPort());
			TServer server = new TNonblockingServer(arg);
			server.serve();
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
